<?
$data = json_decode(@file_get_contents("php://input") ,true);

$url = "http://shanxi.cltt.org/Web/Login/PSCP01001.aspx";

$post = "txtStuID=&txtCertificateNO=&txtCardNO=&__VIEWSTATE=&txtIDCard=".rawurlencode($data['idcard'])."&btnLogin=%E6%9F%A5++%E8%AF%A2&txtName=".rawurlencode($data['name']);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$output = curl_exec($ch);

//$output=str_replace(array("/r","/n","/t","/s"), '', $output);

curl_close($ch);

function get_tag_data($html, $tag, $attr, $value)
{
    $regex = "/<$tag.*?$attr=\".*?$value.*?\".*?>(.*?)<\/$tag>/is";
    //echo $regex . "<br>";
    preg_match_all($regex, $html, $matches, PREG_PATTERN_ORDER);
    return $matches[1];
}

$result = get_tag_data($output, "td", "bgcolor", "#F6f6f6");


for ($i = 0; $i < count($result); $i++) {
    $result[$i] = trim($result[$i]);
}

preg_match('/<img.+src=\"?(.*)\"?.+>/i', $result[4], $match);
$img  = 'http://shanxi.cltt.org/Web/' . substr($match[1], 4);

//http://shanxi.cltt.org/Web/common/GeneratePhotoByStuID.ashx?stuID=1403319070334


$result = array('err' => 0, $result[1], $result[3], $result[6], $result[8], $result[10], $result[12], $result[14], $result[16], $result[18], $result[20], $img);
exit(json_encode($result));
